package com.zzg.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zzg.api.JobConfigService;
import com.zzg.component.ApplicationContextProvider;
import com.zzg.entity.JobConfig;
import com.zzg.util.SchedulerUtil;

@Controller
public class JobController {
	@Autowired
	private JobConfigService service;
	@Autowired
	private ApplicationContextProvider provider;
	
	@RequestMapping(value ="/addJob", method = RequestMethod.GET)
	@ResponseBody
	public void addJob(){
		// 定时任务工具类
		SchedulerUtil util = new SchedulerUtil();
		
		JobConfig jobConfig = new JobConfig();
		jobConfig.setCreateAt(new Date());
		jobConfig.setCronTime("0/8 * *  * * ?");
		jobConfig.setFullEntity("com.zzg.job.CustomizeJob");
		jobConfig.setGroupName("customize");
		jobConfig.setName("My Customize");
		jobConfig.setStatus(1);
		service.insert(jobConfig);
		
		util.createScheduler(jobConfig, provider.getApplicationContext());
		System.out.println("新增任务完成");
		
	}

}
